/**
 * Description:
 * Class Name:ClientThread
 * Date:2022/5/24 9:30
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第17章_网络编程._17_3_基于TCP协议的网络编程._17_3_4_为服务器加入多线程;

import 疯狂Java讲义.第17章_网络编程._17_3_基于TCP协议的网络编程._17_3_3_使用Socket进行通信.Client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class ClientThread implements Runnable{
    private Socket socket;
    // 该线程所处理的Socket对应的输入流
    BufferedReader br = null;

    public ClientThread(Socket socket) throws IOException{
        this.socket = socket;
        br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    }

    @Override
    public void run() {
        try {
            String content = null;
            // 不断地读取Socket输入流中的内容，并将这些内容打印输出
            while ((content = br.readLine()) != null){
                System.out.println(content);
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
}
